/**
 *******************************************************************************************************************************************
 * @file        mem_sdram.h
 * @brief       管理片内 SDRAM 存储空间
 * @details     Apply to On-Chip SDRAM
 * @since       Change Logs:
 * Date         Author       Notes
 * 2023-02-23   lzh          the first version
 * @remark      提供两类不同的实现方式 : LVGL内建 与 自定义实现
 *******************************************************************************************************************************************
 * @attention
 *
 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS WITH CODING INFORMATION
 * REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. AS A RESULT, SYNWIT SHALL NOT BE HELD LIABLE
 * FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT
 * OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN CONN-
 * -ECTION WITH THEIR PRODUCTS.
 *
 * @copyright   2012 Synwit Technology
 *******************************************************************************************************************************************
 */
#ifndef __MEM_SDRAM_H__
#define __MEM_SDRAM_H__

#include "SWM341.h"

/**
 * @def ALIGN_UP(size, align)
 * 返回按照 align 对齐 size 后的值(向上对齐), 且 align 必须能被 2 整除(取值 1 例外)
 * @eg  ALIGN_UP(10, 4) == 12
 */
#define ALIGN_UP(size, align)           (((size) + (align) - 1) & ~((align) - 1))

/**
 * @def ALIGN_DOWN(size, align)
 * 返回按照 align 对齐 size 后的值(向下对齐), 且 align 必须能被 2 整除(取值 1 例外)
 * @eg  ALIGN_DOWN(10, 4) == 8
 */
#define ALIGN_DOWN(size, align)      	((size) & ~((align) - 1))

/**
 * @brief       申请一块内存
 * @param [in]  size    : 期望分配的内存块大小
 * @retval      !NULL   : 分配的内存块首地址
 * @retval      NULL    : error
 */
void *sdram_malloc(size_t size);

/**
 * @brief       释放一块内存
 * @param [in]  *ptr  : 分配的内存块首地址
 * @retval      0     : success
 * @retval      other : error code
 */
uint8_t sdram_free(void *ptr);

/**
 * @brief   获取空闲可用内存大小
 * @param   /
 * @retval  内存池剩余可用内存大小
 */
size_t sdram_get_idle_size(void);

#endif //__MEM_SDRAM_H__
